package web.study.freemarker;

import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.jsp.PageContext;

import freemarker.template.Configuration;
import freemarker.template.Template;

public class FirstFreemarker
{
    public void execute(PageContext pageContext)
        throws Exception
    {
        Configuration cfg = new Configuration();
        cfg.setServletContextForTemplateLoading(pageContext.getServletContext(), "WEB-INF/templates/ftl");
        
        Map<String, String> root = new HashMap<String, String>();
        root.put("name", "Tom");
        
        Template t = cfg.getTemplate("test.ftl");
        
        Writer out = pageContext.getResponse().getWriter();
        
        t.process(root, out);
    }
}
